﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Handlers.SessionHandler;
using ETL.Business.Models;
using ETL.Common;
using ETL.Common.Logging;
using ETL.DataAccess;

namespace ETL.Business.Helpers
{
    public class GetUserId
    {
        private readonly ProjectUserRepository _prjUserRepository;
        // constructor
        public GetUserId()
        {
            _prjUserRepository = new ProjectUserRepository();
        }
        public virtual string Execute(string userId)
        {
            try
            {
                string result = string.Empty;

                // get project_all_names item from db
                var prjAllNamesItem = _prjUserRepository.GetUserById(userId);

                // check null
                if (prjAllNamesItem != null)
                {
                    var prjUserModel = new ProjectUserModel(prjAllNamesItem);

                    // set session variables
                    (new SetSessionData()).Execute(Constants.SessionVars.EngType, prjUserModel.Type);

                    // set return value
                    result = prjUserModel.Type;
                }
                return result;
            }
            catch (Exception ex)
            {
                LogService.Service.Error(ex);
                return string.Empty;
            }
        }
    }
}
